package Tree;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-04-01
 * Time: 09:49
 */
public class MyTreeMap {
    public static void main(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("A",1);
        treeMap.put("B",2);
        treeMap.put("C",3);
        //get
        System.out.println(treeMap.get("A"));//输出1
        System.out.println(treeMap.get("B"));//输出2
        System.out.println(treeMap.get("C"));//输出3
        //getOrDefault
        System.out.println(treeMap.getOrDefault("A", -1));//输出1
        System.out.println(treeMap.getOrDefault("a", -1));//输出-1
        //put
        treeMap.put("C", 30);
        System.out.println(treeMap.get("C"));//输出30
        //remove
        treeMap.remove("C");
        System.out.println(treeMap.getOrDefault("C", -1));//输出-1
        //keySet
        Set<String> strings = treeMap.keySet();
        System.out.println(strings);//输出[A, B]
        //values
        Collection<Integer> values = treeMap.values();
        System.out.println(values);//输出[10,2]
        //entrySet
        Set<Map.Entry<String, Integer>> entries = treeMap.entrySet();
        System.out.println(entries);//输出[A=10, B=2]
        //containsKey
        System.out.println(treeMap.containsKey("A"));//输出true
        System.out.println(treeMap.containsKey("C"));//输出false
        //containsValue
        System.out.println(treeMap.containsValue(1));//输出true
        System.out.println(treeMap.containsValue(30));//输出false
        //size
        System.out.println(treeMap.size());//输出2
        //isEmpty
        System.out.println(treeMap.isEmpty());//输出false
        //clear
        treeMap.clear();
    }
}